package cn.tianyun.pethome.login.controller;

import cn.tianyun.pethome.basic.exception.BusinessException;
import cn.tianyun.pethome.basic.util.AjaxResult;
import cn.tianyun.pethome.login.domain.RegisterVo;
import cn.tianyun.pethome.login.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping
    public AjaxResult registerUser(@RequestBody RegisterVo registerVo){
        try {
            registerService.registerUser(registerVo);
            return AjaxResult.creat().setSuccess(true);
        }catch (BusinessException e){
            return AjaxResult.creat().setSuccess(false).setMsg(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.creat().setSuccess(false).setMsg("网络故障");
        }
    }
}
